package com.peak.distribution.config.security;

import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.peak.distribution.enums.Constants;

import lombok.Data;

@Data
public class SessionUser implements UserDetails {

	private static final long serialVersionUID = Constants.DISTRIBUTION_VERSION;

	/** user的id */
	private Integer id;
	
	/** 代理商ID */
	private Integer agentId;

	/** 登录名 */
	private String username;

	/** 密码 */
	private String password;

	/** 头像 */
	private String headUrl;

	/** 姓名 */
	private String name;

	/** 手机号码 */
	private String mobileNo;

	/** 是否需要密码，默认不需要，重置密码的时候设置为Y */
	private Boolean needModifyPassword;

	/** 状态 */
	private Boolean status;

	/** 权限列表 */
	private Collection<? extends GrantedAuthority> authorities = Lists.newArrayList();
	
	/** 所属角色 */
	private String roleName;
	
	/** 登录后跳转页面 */
	private String defaultSuccessUrl;

	/** 测试账户，支付的时候只需要1分钱 */
	private Boolean isTest;

	@Override
	public String getUsername() {
		return username;
	}

	@JsonIgnore
	@Override
	public String getPassword() {
		return password;
	}

	@JsonIgnore
	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return authorities;
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return this.status.booleanValue();
	}

}
